function db(sql, func){
  var mysql = require('mysql');
  var connection = mysql.createConnection({
    host:     'localhost',
    user:     'root',
    password: '',
    database: 'node'
  });
  connection.connect();
  var query = connection.query(sql);
  query.on('error', function(err){
    console.log(err);
    console.log(sql);
    return 'err is: ' + err;
  });
  query.on('result', function(rows){
    console.log(rows);
    console.log(sql);
    func(rows);
    return rows;

  });
  query.on('end', function(){
    console.log("query end");
    connection.destroy();
  });
}

exports.db = db;

